package kontroler;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import widok.Widok;
import model.Model;

public class Kontroler {

	private Model model;
	private Widok widok;

	public Kontroler(Model model, Widok widok) {
		this.model = model;
		this.widok = widok;

		widok.addMultiplyListener(new MultiplyListener());
		widok.addClearlistener(new CleanerListener());
	}

	class MultiplyListener implements ActionListener {

		@Override
		public void actionPerformed(ActionEvent arg0) {
			String userInput = "";

			try {
				userInput = widok.getUserInput();
				model.multipleBy(userInput);
				widok.setTotal(model.getValue());
			} catch (Exception e) {
				widok.showError("Wystapil blad: '" + userInput + "'");
			}

		}

	}
	
	class CleanerListener implements ActionListener {

		@Override
		public void actionPerformed(ActionEvent e) {
			// TODO Auto-generated method stub
			model.kasuj();
			widok.reset();
		}
		
	}

}
